package com.ruoyi.basedocument.controller;

import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basedocument.domain.BomRawmaterial;
import com.ruoyi.basedocument.service.IBomRawmaterialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * BOM原材料Controller
 * 
 * @author ruoyi
 * @date 2024-09-12
 */
@RestController
@RequestMapping("/bomcostestimation/basedocument/rawmaterial")
public class BomRawmaterialController extends BaseController
{
    @Autowired
    private IBomRawmaterialService bomRawmaterialService;

    /**
     * 查询BOM原材料列表
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:rawmaterial:list')")
    @GetMapping("/list")
    public TableDataInfo list(BomRawmaterial bomRawmaterial)
    {
        startPage();
        List<BomRawmaterial> list = bomRawmaterialService.selectBomRawmaterialList(bomRawmaterial);
        return getDataTable(list);
    }

    /**
     * 导出BOM原材料列表
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:rawmaterial:export')")
    @Log(title = "BOM原材料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BomRawmaterial bomRawmaterial)
    {
        List<BomRawmaterial> list = bomRawmaterialService.selectBomRawmaterialList(bomRawmaterial);
        ExcelUtil<BomRawmaterial> util = new ExcelUtil<BomRawmaterial>(BomRawmaterial.class);
        util.exportExcel(response, list, "BOM原材料数据");
    }

    /**
     * 获取BOM原材料详细信息
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:rawmaterial:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(bomRawmaterialService.selectBomRawmaterialById(id));
    }

    /**
     * 新增BOM原材料
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:rawmaterial:add')")
    @Log(title = "BOM原材料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BomRawmaterial bomRawmaterial)
    {
        return toAjax(bomRawmaterialService.insertBomRawmaterial(bomRawmaterial));
    }

    /**
     * 修改BOM原材料
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:rawmaterial:edit')")
    @Log(title = "BOM原材料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BomRawmaterial bomRawmaterial)
    {
        return toAjax(bomRawmaterialService.updateBomRawmaterial(bomRawmaterial));
    }

    /**
     * 删除BOM原材料
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:rawmaterial:remove')")
    @Log(title = "BOM原材料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        int rows = bomRawmaterialService.deleteBomRawmaterialByIds(ids);
        return toAjax(rows+1);
    }

    /**
     * 引入原材料价格
     */
    @GetMapping("/introductionPrice/{numbers}")
    public HashMap introductionPrice(@PathVariable String[] numbers)
    {
        return bomRawmaterialService.introductionPrice(numbers);
    }
}
